package com.api.user.controller;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.CommodityCategory;
import com.api.user.service.CommodityCategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.api.core.annotation.PowerEnable;
import io.swagger.annotations.*;



/**
* Created by wanghuiwen on 2021/04/12.
*/
@PowerEnable(name = "商品分类",url = "/commodity/category")
@Api(value = "商品分类", tags = {"商品分类"})
@RestController
@RequestMapping("/commodity/category")
public class CommodityCategoryController extends Ctrl{
    @Resource
    private CommodityCategoryService commodityCategoryService;

    @ApiOperation(value = "商品分类添加", tags = {"商品分类"}, notes = "商品分类添加")
    @PostMapping(value="/add",name="商品分类添加")
    public Result add(@ApiParam CommodityCategory commodityCategory) {

        return  commodityCategoryService.add(commodityCategory);
    }

    @ApiOperation(value = "商品分类删除", tags = {"商品分类"}, notes = "商品分类删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "commodityCategoryId",required=true, value = "商品分类id", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/delete",name="商品分类删除")
    public Result delete(@RequestParam Long commodityCategoryId) {

        return commodityCategoryService.delete(commodityCategoryId);
    }




    @ApiOperation(value = "商品分类-列表", tags = {"商品分类"}, notes = "商品分类-列表")
    @ApiImplicitParams({
//        @ApiImplicitParam(name = "search", value = "查询条件json", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "order", value = "排序json", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "page", value = "页码", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "size", value = "每页显示的条数", dataType = "String", paramType = "query", defaultValue = "10")
    })
    @PostMapping(value = "/list", name = "商品分类-列表")
    public Result list(
                       @RequestParam(defaultValue = "{}") String order,
                       @RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "10") Integer size) {
        Map<String,Object> params = new HashMap<>();

        return commodityCategoryService.list(params, order, page, size);
    }
}
